import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { TypeOrmModule } from "@nestjs/typeorm";
import databaseConfig from "./config/database.config";
import appConfig from "./config/app.config";
import { AppService } from "./app.service";
import { User } from "./modules/user/entities/user.entity";

// 导入模块
import { UserModule } from "./modules/user/user.module";
import { ProductModule } from "./modules/product/product.module";
import { OrderModule } from "./modules/order/order.module";
import { PointsModule } from "./modules/points/points.module";
import { AuthModule } from "./modules/auth/auth.module";
import { AddressModule } from "./modules/address/address.module";
import { UploadModule } from "./modules/upload/upload.module";

@Module({
	imports: [
		// 配置模块
		ConfigModule.forRoot({
			isGlobal: true,
			load: [databaseConfig, appConfig],
			envFilePath: ".env",
		}),

		// 数据库模块
		TypeOrmModule.forRootAsync({
			inject: [ConfigService],
			useFactory: (configService: ConfigService) =>
				configService.get("database"),
		}),

		// 实体模块
		TypeOrmModule.forFeature([User]),

		// 业务模块
		UserModule,
		ProductModule,
		OrderModule,
		PointsModule,
		AuthModule,
		AddressModule,
		UploadModule,
	],
	providers: [AppService],
})
export class AppModule {}
